<template>
  <div class="box">
    <div class="fimg">
      <i class="iconfont icon-angle-left" @click="goback"></i>
      <img :src="item.poster" alt="" class="poster" />
    </div>
    <div class="fdetail">
      <span class="s1">{{ item.name }}</span>
      <span class="s2">{{ a }}</span>
      <span class="s3">{{ item.grade }}分</span>
      <div class="fname">{{ item.category }}</div>
      <div class="ftime">{{ item.premiereAt | setTime }}上映</div>
      <div class="fadd">{{ item.nation }} | {{ item.runtime }}</div>
      <!--       <div :class="{ hide, fde }">
        {{ item.synopsis }}
      </div>
 -->
      <!-- 高度 -->
      <div class="desc" :style="{ height }">
        {{ item.synopsis }}
      </div>
      <div>
        <i :class="jiantou" @click="change"></i>
      </div>
    </div>
    <div class="kong"></div>
    <div class="actors">
      <div class="title">演职人员</div>
      <!-- 轮播图插件 -->
      <div class="swiper mySwiper">
        <div class="swiper-wrapper">
          <div
            class="swiper-slide"
            v-for="item in item.actors"
            :key="item.name"
          >
            <img :src="item.avatarAddress" width="85" height="117" />
            <div class="aname">{{ item.name }}</div>
            <div class="arole">{{ item.role }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="kong"></div>
    <div class="photos">
      <div class="p1">电影剧照</div>
      <div class="p2">暂无剧照</div>
    </div>
    <div class="xuanbuy">选座购票</div>
  </div>
</template>

<script>
import api from '@/api'
// 导入swiper
import 'swiper/swiper-bundle.min.css'
import Swiper from 'swiper'
export default {
  data() {
    return {
      item: {},
      a: 1,
      /* hide: false,
      fde: true, */
      jiantou: {
        iconfont: true,
        'icon-angle-down': true,
        'icon-angle-up': false
      },
      // 定义高度
      h: '',
      height: ''
    }
  },
  filters: {
    setTime(val) {
      const b = val * 1000
      const data = new Date(b)
      const year = data.getFullYear()
      const month = data.getMonth() + 1
      const ri = data.getDate()
      return year + '-' + month + '-' + ri
    }
  },
  created() {
    const id = this.$store.state.filmId
    this.$store.commit('hideFooter')
    console.log(this.$store.state.footer)
    this.$http.get(api.getMdetail + '?filmId=' + id).then((res) => {
      if (res.status === 0 && res.msg === 'ok') {
        this.item = res.data.film
        this.a = res.data.film.item.name
      }
    })
  },
  beforeDestroy() {
    this.$store.commit('showFooter')
  },
  watch: {
    'item.synopsis': {
      handler() {
        this.$nextTick(() => {
          var t = document.querySelector('.desc').offsetHeight
          this.h = t
          this.height = '30px'
        })
      },
      deep: true
    }
  },
  methods: {
    // 下箭头点击显示电影详情
    change() {
      /* this.fde = !this.fde
      this.hide = !this.hide */
      this.jiantou['icon-angle-down'] = !this.jiantou['icon-angle-down']
      this.jiantou['icon-angle-up'] = !this.jiantou['icon-angle-up']
      // 判断高度
      this.height = this.height === '30px' ? this.h + 'px' : '30px'
    },
    // 从详情页面返回上一页
    goback() {
      this.$router.go(-1)
    }
  },
  mounted() {
    var swiper = new Swiper('.mySwiper', {
      slidesPerView: 3,
      spaceBetween: 30,
      freeMode: true
    })
    console.log(swiper)
  }
}
</script>

<style lang='scss' scoped>
.desc {
  font-size: 13px;
  color: #797d82;
  padding: 5px;
  transition: height 2s ease;
  /* height: 20px; */
  overflow: hidden;
}
.box {
  width: 100%;
  overflow: auto;
  .fimg {
    width: 100%;
    height: 200px;
    overflow: hidden;
    position: relative;
    .poster {
      width: 100%;
      height: 450px;
    }
    i {
      position: absolute;
      top: 20px;
      left: 0;
      font-size: 15px;
      color: white;
    }
  }
  .fdetail {
    width: 100%;
    padding: 10px 10px 0;
    box-sizing: border-box;
    span {
      display: inline-block;
      color: #191a1b;
      font-size: 18px;
      height: 24px;
      line-height: 24px;
      margin-right: 7px;
    }
    .s2 {
      font-size: 9px;
      color: #fff;
      background-color: #d2d6dc;
      height: 14px;
      line-height: 14px;
      padding: 0 2px;
      border-radius: 2px;
    }
    .s3 {
      text-align: right;
      color: #ffb232;
      float: right;
    }
    .fname,
    .ftime,
    .fadd {
      font-size: 13px;
      color: #797d82;
      margin-top: 5px;
      margin-bottom: 5px;
    }
    /* .fde {
      height: 36px;
      margin-top: 12px;
      font-size: 13px;
      color: #797d82;
      display: -webkit-box;
      overflow: hidden;
      text-overflow: ellipsis;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    .hide {
      margin-top: 12px;
      font-size: 13px;
      color: #797d82;
    } */
    div > i {
      display: block;
      font-size: 10px;
      width: 100%;
      height: 12px;
      line-height: 12px;
      text-align: center;
    }
  }
}
.actors {
  padding: 3px 10px;
  box-sizing: border-box;
  .title {
    margin-bottom: 10px;
    font-size: 16px;
    text-align: left;
    color: #191a1b;
  }
  .aname,
  .arole {
    padding-top: 3px;
    font-size: 12px;
    color: #191a1b;
    width: 85px;
    height: 15px;
    text-align: center;
    line-height: 15px;
  }
  .arole {
    color: #797d82;
  }
}
.swiper-slide {
  width: 85px;
  margin: 0 5px;
}
.kong {
  width: 100%;
  height: 5px;
  background-color: #f4f4f4;
}
.photos {
  padding: 3px 10px 50px;
  box-sizing: border-box;
  .p1 {
    margin-bottom: 10px;
    font-size: 16px;
    text-align: left;
    color: #191a1b;
  }
  .p2 {
    width: 100%;
    height: 80px;
    line-height: 80px;
    text-align: center;
    font-size: 18px;
    box-sizing: border-box;
  }
}
.xuanbuy {
  position: fixed;
  bottom: 0;
  left: 0;
  height: 49px;
  width: 100%;
  text-align: center;
  background-color: #ff5f16;
  color: #fff;
  font-size: 16px;
  line-height: 49px;
  z-index: 2;
}
</style>
